{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5> {if $type == 1}详情{else /}编辑{/if}</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">
                        <input type="hidden" name="l_id" value="{$l_id}" />
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input {if $type == 1}disabled{/if} type="text" name="l_title" lay-verify="required" placeholder="标题"  value="{$info.l_title}" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">状态：</label>
                            <div class="layui-input-block">
                                <input {if $type == 1}disabled{/if} type="radio" name="l_status" value="1" title="上架" {if $info.l_status==1}checked{/if} />
                                <input {if $type == 1}disabled{/if} type="radio" name="l_status" value="2" title="下架" {if $info.l_status==2}checked{/if} />
                            </div>
                        </div>
                        <!--xm-select-radio=""-->
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">所属琴行：</label>
                            <div class="layui-input-block">
                                {if $info['l_type'] == 1}
                                <select {if $type == 1 || $Think.session.groupid == 2}disabled{/if} id="l_piano" lay-verify="required" lay-filter="role" name="l_piano" lay-search>
                                {else /}
                                <select {if $type == 1 || $Think.session.groupid == 2}disabled{/if} id="l_piano" lay-verify="required" name="l_piano" xm-select="select2" xm-select-search="" xm-select-search-type="dl">
                                {/if}
                                    <option value="">请选择</option>
                                    {foreach name="panio" item="v"}
                                    <option value="{$v.pa_id}" {if in_array($v.pa_id,$info.l_piano)}selected{/if}>{$v.pa_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {if $info['l_type'] == 1}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择学生：</label>
                            <div class="layui-input-block">
                                <select {if $type == 1}disabled{/if} id="l_student" lay-verify="required" name="l_student" lay-search>
                                    <option value="">请选择</option>
                                    {foreach name="students" item="v"}
                                    <option value="{$v.id}" {if $info.l_student==$v.id}selected{/if}>{$v.name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {/if}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10" id="banner_content">
                            <label class="layui-form-label">内容：</label>
                            <div class="layui-input-block" {if $type == 1}disabled{/if} id="LAY_editor" lay-verify="editor">
                                <p {if $type == 1}disabled{/if}>{$info.l_content}</p>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                {if $type == 0}
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                {/if}
                                <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">返回</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var editor = wk.wang({elem:'#LAY_editor'});
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.verify({
            editor:function(value,item){
                if(editor.txt.html() == '<p><br></p>'){
                    return '请填写内容';
                }
            }
        });
        form.on('submit(component-form-element)', function (data) {
            data.field.l_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('memberEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        })
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(role)', function(data){
            var pid = data.value;
            if(pid == ''){
                $('#l_student').empty();
            }else{
                $.ajax({
                    url:"{:url('getUserByPiano')}",
                    dataType: 'json',
                    data : 'pid='+pid,
                    type: 'post',
                    success: function (returndata) {
                        if(returndata.code == 200){
                            var data = returndata.msg;
                            $("#l_student").empty();//清空下拉框的值
                            $('#l_student').append(new Option('请选择学生', ' '));// 下拉菜单里添加元素
                            $.each(data, function (index, item) {
                                $('#l_student').append(new Option(item.name, item.id));// 下拉菜单里添加元素
                            });
                            layui.form.render("select");//重新渲染 固定写法
                        }else{
                            alert ('error');
                        }
                    }
                });
            }
        });
    });
</script>

</body>
</html>
